'use strict';

const Service = require('egg').Service;

class ScoresService extends Service {
    async addscores(obj){
        let {name,stu,theory,skill}=obj;
        let res=await this.app.mysql.query(`inster into scores (name,stu,theory,skill) value ('${name}','${stu}','${theory}','${skill}')`);
        return res;
    }
  async scores(obj) {
    let {name,stu,theory,skill}=obj;
    let res=await this.app.mysql.query(`insert init scores (name,stu,theory,skill) values ('${name}','${stu}','${theory}','${skill}')`);
    return res;
  }
  async listscores(page,limit,search,sortname,order){
      let arr=['asc','desc']

      let con=await this.app.mysql.query(`select count(*) from scores where name like '%${search}%'`);
     console.log(con);
      let startIndex=(page-1)*limit;//开始下标
      let sql=`select*from scores where name like '%${search}%' order by${sortname}*1 ${order} limit ${startIndex},${limit}`;
      let res=await this.app.mysql.query(sql);
      return res;
  }

  async updatescores(obj){
      let {name,stu,theory,skill,id}=obj;
      let sql=`update scores set name='${name}',stu='${stu}',theory='${theory}',skill='${skill}',where id='${id}'`
      let res=await this.app.mysql.query(sql);
      return res;
    }

    async delscores(id){
        let {name,stu,theory,skill,id}=obj;
        let sql=`update scores set name='${name}',stu='${stu}',theory='${theory}',skill='${skill}',where id='${id}'`
        let res=await this.app.mysql.query(sql);
        return res;
    }

    async getdate(){
        let sql=`select *from scores where skill >=90 and theory >=90`;
        let pass=await this.app.mysql.query(sql);
        let sql2=`select *from scores where skill <90 and theory <90`;
        let nopass=await this.app.mysql.query(sql2);
        return {
            pass,
            nopass
        }
    }

}

module.exports = ScoresService;
